const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: 0,
    orderList: [{
        ddNum: '订单编号：201920630026299219',
        state: '未付款',
        ddImg: '../../images/2.jpg',
        ddName: '红极参大叔大婶奥术大师分阿帆水电费沙发萨达阿打算啊啊啊dfdsa 首付是水电费分水电费额发送到分色分分是',
        ddGuige: '规格：蓝色_XS',
        rmb: '102200.00',
        num: '×1',
        numAll: '1000.00',
        numAll2: '0.00'
      },
      {
        ddNum: '订单编号：201920630026299219',
        state: '已付款',
        ddImg: '../../images/2.jpg',
        ddName: '红极参',
        ddGuige: '规格：蓝色_XS',
        rmb: '1000.00',
        num: '×1',
        numAll: '1000.00',
        numAll2: '0.00'
      },
    ],
    selectArray: [{
      "id": "10",
      "text": "支付宝"
    }, {
      "id": "21",
      "text": "微信支付"
    }],
    hostUrl: app.globalData.hostUrl,
    isShow: false,
    isShow1: false
  },
  // 弹窗
  guanbi: function() {
    this.setData({
      isShow: false,
      isShow1: false,
    })
  },
  zhifu: function() {
    this.setData({
      isShow: true,
      isShow1: true
    })
  },
  /** 
   * 滑动切换tab 
   */
  bindChange: function(e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  /** 
   * 点击tab切换 
   */
  swichNav: function(e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
    that.getOrderList();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // 获取屏幕高度
    this.setData({
      windowHeight: wx.getSystemInfoSync().windowHeight,
      // currentTab: options.currentTab
    })
    this.getOrderList();

    // 滑块
    var that = this;
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
  },
  getOrderList: function() { //读取订单
    var that = this;

    wx.request({
      url: app.globalData.apiUrl + 'Order/getOrderList',
      data: {
        // opt: 'getOrderList',
        userId: wx.getStorageSync('userId'),
        state: that.data.currentTab, //
      },
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        if (res.data != null) {
          that.setData({
            orderList: res.data,
          })
        }
      }
    })
  },
  pay: function (e) {//支付
    console.log(e)
    // var payway=r.

    var that = this;
    if (e.currentTarget.dataset.payway == 2) {
      wx.request({
        url: app.globalData.apiUrl + 'Pay/GetUnifiedOrderResult',
        data: {
          // opt: 'GetUnifiedOrderResult',
          userId: wx.getStorageSync('userId'),
          id: e.currentTarget.dataset.orderid,//订单id
          // typeId: 2,
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res, '支付返回信息')
          // return ;
          wx.requestPayment({
            'timeStamp': res.data.timeStamp,
            'nonceStr': res.data.nonceStr,
            'package': res.data.package,
            'signType': 'MD5',
            'paySign': res.data.paySign,
            'success': function (res) {
              console.log(res)
              that.onLoad();
            },
            'fail': function (res) {
              that.onLoad();

            },
            'complete': function (res) {
              that.onLoad();

            }
          })

        }
      })
    } else {
      wx.navigateTo({
        url: '../../new_inter/zhifu/zhifu?orderid=' + e.currentTarget.dataset.orderid + '&type=购买商品',
      })
    }

  },
  //确认收货
  querenshouhuo: function (e) {
    var id = e.currentTarget.dataset.id;
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'order/querenshouhuo',
      data: {
        userId:wx.getStorageSync('userId'),
        id: id,
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data != null) {
          if (res.data.status == 1) {
            wx.showToast({
              title: '签收成功',
              icon: 'success',
              duration: 2000
            });
            that.getOrderList(id);//读取订单
            // that.getOrder(id);//读取订单
            // that.getAddressList();
            // that.getOrderSate(id);
          } else {
            wx.showToast({
              title: '签收失败',
              icon: 'error',
              duration: 2000
            })
          }

        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  //删除
  del: function (e) {
    var that = this;
    var orderid = e.currentTarget.dataset.orderid;
    wx.navigateTo({
      url: '/pages/del_pwd/del_pwd?type=购物删除' + "&orderid=" + orderid,
    })

    // wx.request({
    //   url: app.globalData.apiUrl + 'User/delDo',
    //   data: {
    //     // opt: 'getUser',
    //     OrderID: orderid,

    //   },
    //   header: {
    //     'content-type': 'application/json'
    //   },
    //   success: function (res) {
    //     console.log(res, '用户信息')
    //     if (res.data.status=1) {
    //       wx.showToast({
    //         title: res.data.message,
    //       })
    //       that.yuyue_kanfang();
    //     }else{
    //       wx.showToast({
    //         title: res.data.message,
    //       })
    //     }
    //   }

    // })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  daifu: function() {
    wx.navigateTo({
      url: '../daifu/daifu',
    })
  },
  daifa: function() {
    wx.navigateTo({
      url: '../daifa/daifa',
    })
  },
  daishou: function() {
    wx.navigateTo({
      url: '../daishou/daishou',
    })
  },
  daiping: function() {
    wx.navigateTo({
      url: '../daiping/daiping',
    })
  },
  dingdanils: function(e) {
    console.log(e)
    var orderid = e.currentTarget.dataset.orderid;
    wx.navigateTo({
      url: '../dingdanils/dingdanils?orderid=' + orderid,
    })
  },
  cleardd: function() {
    wx.navigateTo({
      url: '../quxiaodd/quxiaodd',
    })
  },
  back: function(){
    wx.reLaunch({       //关闭当前所有页面
      url: '/pages/personal/personal',
    })
  },
  find_wuliu:function(e){
    var orderid = e.currentTarget.dataset.orderid;
    wx.navigateTo({
      url: '../../wuliu/wuliu?orderid=' + orderid,
    })
  }

})